package com.DR;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;

public class UI extends JPanel {

    public int X0= 135, Y0 = 100;
    public int SIZE = 20,LINE = 30;

    public void initUI() {
        JFrame frame = new JFrame();
        frame.setTitle("DigitRecognition");
        frame.setSize(900,900);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        this.setBackground(Color.white);
        frame.add(this);

        JButton buttonRefresh = new JButton("刷新");
        JButton buttonRecognition = new JButton("识别");
        JButton buttonEntry = new JButton("录入");
        JLabel jLabel = new JLabel("请选择录入的数字：");
        String[] num = {"1","2","3","4","5","6","7","8","9","0"};
        JComboBox<String> comboBox = new JComboBox<>(num);

        this.add(jLabel);
        this.add(comboBox);
        this.add(buttonRefresh);
        this.add(buttonRefresh);
        this.add(buttonRecognition);
        this.add(buttonEntry);

        frame.setVisible(true);
        //监听器
        Graphics g = this.getGraphics();
        Listener listener = new Listener(g);
        this.addMouseListener(listener);
        this.addMouseMotionListener(listener);
        buttonRefresh.addActionListener(listener);
        buttonRecognition.addActionListener(listener);
        buttonEntry.addActionListener(listener);
        comboBox.addActionListener(listener);
        listener.setUi(this);
    }
    public void paint(Graphics g) {
        super.paint(g);
        for (int i = 0; i < LINE; i++) {
            g.drawLine(X0,Y0+i*SIZE,(LINE-1)*SIZE+X0,Y0+i*SIZE);
            g.drawLine(X0+i*SIZE,Y0,X0+i*SIZE,(LINE-1)*SIZE+Y0);
        }
    }

    public static void main(String[] args) {
        UI ui = new UI();
        ui.initUI();
    }
}
